package ru.papergames.battleserver.network.serverpackets.flashuser;

import ru.papergames.battleserver.model.battle.AbstractBattle;
import ru.papergames.battleserver.model.battle.GameBall;

import java.util.Collections;
import java.util.List;

/**
 * @author : atroshanin
 */
public class BattleNewBallsThrown extends PaperGameServerPacket {

    private List<GameBall> balls;
    private AbstractBattle battle;

    public BattleNewBallsThrown(AbstractBattle battle, List<GameBall> balls) {
        this.battle = battle;
        this.balls = balls;
    }

    public List<GameBall> getBalls() {
        return Collections.unmodifiableList(balls);
    }

    @Override
    protected int getPacketId() {
        return BATTLE_NEW_BALLS_THROWN_PACKET_ID;
    }

    @Override
    protected void writePacketData() {
        // TODO: action time
        writeD(battle.getBattleOrderId());
        writeH(balls.size());
        for (GameBall ball : balls) {
            writeH(ball.getCell().getX());
            writeH(ball.getCell().getY());
            writeH(ball.getColor().getId());
        }
    }

}
